package com.cloud.utils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 集合操作工具
 * 差集、交集、补集
 */
public class ListUtils {

    // 旧集合
    private List<Long> lodList;

    // 新集合
    private List<Long> newList;

    public ListUtils(List<Long> lodList, List<Long> newList) {
        this.lodList = lodList;
        this.newList = newList;
    }

    public ListUtils(Long[] lodList, Long[] newList) {
        this.lodList = Arrays.asList(lodList);
        this.newList = Arrays.asList(newList);
    }

    // 旧集合元素差集
    public List<Long> getSubtract() {
        return lodList.stream().filter(item -> !newList.contains(item)).collect(Collectors.toList());
    }

    // 2个集合元素交集
    public List<Long> getIntersection() {
        return lodList.stream().filter(item -> newList.contains(item)).collect(Collectors.toList());
    }

    // 新集合元素补集
    public List<Long> getAddendum() {
        return newList.stream().filter(item -> !lodList.contains(item)).collect(Collectors.toList());
    }

}
